package com.sc.nft.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.admin.request.SortRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.dto.MallPreferenceActivityAdminDTO;
import com.sc.nft.entity.vo.MallPreferenceActivityAdminVO;
import com.sc.nft.entity.vo.MallPreferenceActivityVO;
import com.sc.nft.service.MallPreferenceActivityService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @Author：LiGen
 * @Package：com.sc.nft.admin.controller
 * @Project：sc_metago
 * @name：MallPreferenceActivityController
 * @Date：2024/3/12 10:49
 * @Filename：MallPreferenceActivityController
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/preference")
@Api(tags = "好物优选活动模块")
public class MallPreferenceActivityController {

    private final MallPreferenceActivityService mallPreferenceActivityService;

    @ApiOperation(value = "列表", notes = "列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/page", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<MallPreferenceActivityAdminDTO> pageAdmin(@RequestBody MallPreferenceActivityAdminVO mallPreferenceActivityAdminVO) {
        Page<MallPreferenceActivityAdminDTO> mallPreferenceActivityAdminDTOPage = mallPreferenceActivityService.pageAdmin(mallPreferenceActivityAdminVO);
        return PageResult.success(mallPreferenceActivityAdminDTOPage);
    }

    @ApiOperation(value = "添加", notes = "添加", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result add(@Valid @RequestBody MallPreferenceActivityVO vo) {
        mallPreferenceActivityService.add(vo);
        return Result.success();
    }

    @ApiOperation(value = "移除", notes = "移除", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/remove", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result remove(@Valid @RequestBody IdRequest request) {
        mallPreferenceActivityService.remove(request.getId());
        return Result.success();
    }

    @ApiOperation(value = "好物优选活动上架", notes = "分享购活动上架", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/enable", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result enable(@Valid @RequestBody IdRequest idRequest) {
        mallPreferenceActivityService.updateStatus(idRequest.getId(),Boolean.TRUE);
        return Result.success();
    }

    @ApiOperation(value = "好物优选活动下架", notes = "分享购活动下架", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/disable", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result disable(@Valid @RequestBody IdRequest idRequest) {
        mallPreferenceActivityService.updateStatus(idRequest.getId(),Boolean.FALSE);
        return Result.success();
    }

    @ApiOperation(value = "好物优选活动排序", notes = "好物优选活动排序", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updateSort", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateSort(@RequestBody SortRequest request) {
        mallPreferenceActivityService.updateSort(request.getId(),request.getSort());
        return Result.success();
    }
}
